#!/usr/bin/perl

$table_output=">table.csv"; # file to spit csv file out to

open TABLE, $table_output or die "Cannot open file $table_output\n";
print TABLE ("Benchmark,BB_Dimensions,BB_Area,Feedthrough_Cells,Wire_Length,Vias,Execution_Time,Memory_Used,Random_Seed\n");

#for($j = 1; $j <= 12; $j++) {
for($j = 1; $j <= 12; $j++) {
  print("Executing main.exe Benchmark/Benchmark$j.net\n");
  my @execute_data = execute_test("main.exe Benchmark/Benchmark$j.net");
  my @temp_array = split(/\s/,$execute_data[7]);
  my $cost = $temp_array[2];
  @temp_array = split(/\s/,$execute_data[8]);
  my $feedthroughs = $temp_array[3];
  @temp_array = split(/\s/,$execute_data[20]);
  my $dimensions = $temp_array[3];
  @temp_array = split(/\s/,$execute_data[21]);
  my $area = $temp_array[3];
  @temp_array = split(/\s/,$execute_data[22]);
  my $vias = $temp_array[2];
  @temp_array = split(/\s/,$execute_data[24]);
  my $time = $temp_array[0];
  my $memory = $temp_array[1]*$temp_array[2];
  my $wirelength = $cost-($feedthroughs*24);
  
  print(@execute_data);
  print TABLE ("Benchmark$j,$dimensions,$area,$feedthroughs,$wirelength,$vias,$time,$memory,1531\n");


}

sub execute_test {
# executable name is only input
  my $executable = shift;
  my @info;
  open(EXEC,"time -f '%e %Z %R' ./$executable 2>&1 |") || die "Failed: $!\n";
    while ( <EXEC> ) {
	  push (@info, $_);
    }
  return @info;
}


